package cl.solidit.geomanagement.web.controller.comunication;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import cl.solidit.geomanagement.persistance.model.Propiedad;
import cl.solidit.geomanagement.persistance.model.Visita;

public class JSONProperty {
	static public class JSONVisita {
		private Long id;
		private String cliente;

		private JSONVisita(Long id, String cliente) {
			this.id = id;
			this.cliente = cliente;
		}

		public String getCliente() {
			return cliente;
		}

		public void setCliente(String cliente) {
			this.cliente = cliente;
		}

		public Long getId() {
			return id;
		}

		public void setId(Long id) {
			this.id = id;
		}
	}

	private Long id;
	private Long type;
	private String typeName;
	private Integer visits;
	private Integer status;
	private String statusName;
	private Boolean furinture;
	private Boolean offer;
	private Integer rentOrSale;
	private Integer perseption;
	private String address;
	private String comuna;
	private String created;
	private String visited;
	private String responsable;
	private String lat;
	private String lng;
	private Long number;
	private String meters;
	private String perceptionName;
	private List<JSONVisita> listVisita = new ArrayList<JSONVisita>();
	private Boolean valorEnUf;

	public JSONProperty(Propiedad p) {
		load(p);
	}

	private void load(Propiedad p) {
		this.id = p.getId();
		this.type = p.getTipoPropiedad().getId();
		this.typeName = p.getTipoPropiedad().getNombre();
		this.visits = p.getVisitas().size();
		this.status = p.getEstado().getId();
		this.setStatusName(p.getEstado().getNombre());
		this.furinture = p.getAmoblada();
		this.offer = p.getOfertada();
		this.rentOrSale = p.getVenta() ? 2 : 1;
		this.perseption = p.getPercepcion() == null ? 0 : p.getPercepcion();
		switch (this.perseption) {
		case 1:
			this.perceptionName = "Baja";
			break;
		case 2:
			this.perceptionName = "Media";
			break;
		default:
			this.perceptionName = "Alta";
		}
		this.address = p.getDireccion();
		this.comuna = p.getComuna().getNombre();
		this.setNumber(p.getNumero());
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
		this.created = sdf.format(p.getFechaIngreso());
		this.visited = p.getUltimaVisita() != null ? sdf.format(p
				.getUltimaVisita()) : "";
		this.responsable = p.getAgente() != null ? p.getAgente().getPersona()
				.getNombre() : "";
		this.lat = p.getLatitud();
		this.lng = p.getLongitud();
		this.setMeters(p.getMetrosCuadrados() != null ? p.getMetrosCuadrados()
				.toString() : "");
		this.valorEnUf = p.getValorEnUf();
	}

	public JSONProperty(Propiedad p, List<Visita> visitas) {

		for (Visita visita : visitas)
			listVisita.add(new JSONVisita(visita.getId(), visita.getCliente()
					.getNombre()));
		this.load(p);
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getType() {
		return type;
	}

	public void setType(Long type) {
		this.type = type;
	}

	public Integer getVisits() {
		return visits;
	}

	public void setVisits(Integer visits) {
		this.visits = visits;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Boolean getFurinture() {
		return furinture;
	}

	public void setFurinture(Boolean furinture) {
		this.furinture = furinture;
	}

	public Integer getRentOrSale() {
		return rentOrSale;
	}

	public void setRentOrSale(Integer rentOrSale) {
		this.rentOrSale = rentOrSale;
	}

	public Integer getPerseption() {
		return perseption;
	}

	public void setPerseption(Integer perseption) {
		this.perseption = perseption;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getComuna() {
		return comuna;
	}

	public void setComuna(String comuna) {
		this.comuna = comuna;
	}

	public String getCreated() {
		return created;
	}

	public void setCreated(String created) {
		this.created = created;
	}

	public String getVisited() {
		return visited;
	}

	public void setVisited(String visited) {
		this.visited = visited;
	}

	public String getResponsable() {
		return responsable;
	}

	public void setResponsable(String responsable) {
		this.responsable = responsable;
	}

	public String getLng() {
		return lng;
	}

	public void setLng(String lng) {
		this.lng = lng;
	}

	public String getLat() {
		return lat;
	}

	public void setLat(String lat) {
		this.lat = lat;
	}

	public Long getNumber() {
		return number;
	}

	public void setNumber(Long number) {
		this.number = number;
	}

	public String getMeters() {
		return meters;
	}

	public void setMeters(String meters) {
		this.meters = meters;
	}

	public String getStatusName() {
		return statusName;
	}

	public void setStatusName(String statusName) {
		this.statusName = statusName;
	}

	public String getPerceptionName() {
		return perceptionName;
	}

	public void setPerceptionName(String perceptionName) {
		this.perceptionName = perceptionName;
	}

	public List<JSONVisita> getListVisita() {
		return listVisita;
	}

	public void setListVisita(List<JSONVisita> listVisita) {
		this.listVisita = listVisita;
	}

	public Boolean getValorEnUf() {
		return valorEnUf;
	}

	public void setValorEnUf(Boolean valorEnUf) {
		this.valorEnUf = valorEnUf;
	}

	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public Boolean getOffer() {
		return offer;
	}

	public void setOffer(Boolean offer) {
		this.offer = offer;
	}
	
	

}
